﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css {
    import reprise.data.*;
    import flash.text.*;
    import reprise.css.transitions.*;
    import reprise.css.propertyparsers.*;
    import reprise.controls.csspropertyparsers.*;

    public class CSSDeclaration {

        protected var m_hasDefaultValues:Boolean;
        protected var m_properties:Object;

        public static const TEXT_STYLESHEET:StyleSheet = new StyleSheet();
        protected static const TEXT_PROPERTIES:Object = {textAlign:true, blockIndent:true, fontWeight:true, bullet:true, color:true, fontFamily:true, textIndent:true, fontStyle:true, kerning:true, leading:true, marginLeft:true, letterSpacing:true, marginRight:true, fontSize:true, tabStops:true, target:true, textDecoration:true, url:true};
        protected static const g_propertyToParserTable:Object = {};
        protected static const g_textStyleNames:Object = {};
        public static const INHERITABLE_PROPERTIES:Object = {};
        protected static const g_defaultPropertiesRegistered:Boolean = registerDefaultProperties();

        protected static var m_thrownErrors:Object = {};

        public function CSSDeclaration(){
            m_properties = {};
        }
        public function toTextFormatObject():Object{
            var _local2:String;
            var _local1:Object = {};
            for (_local2 in m_properties) {
                if (TEXT_PROPERTIES[_local2]){
                    _local1[_local2] = CSSProperty(m_properties[_local2]).valueOf();
                };
            };
            _local1.color = ((_local1.color) && (AdvancedColor(_local1.color).toString().substr(0, 7)));
            return (_local1);
        }
        public function toString():String{
            var _local3:String;
            var _local4:CSSProperty;
            var _local1 = "CSSDeclaration\n{\n";
            var _local2:Array = [];
            for (_local3 in m_properties) {
                _local4 = CSSProperty(m_properties[_local3]);
                _local2.push((((((("\t" + _local3) + " : ") + _local4.specifiedValue()) + ((_local4.unit()) || (""))) + "; //") + ((_local4.cssFile()) || ("[no file]"))));
            };
            _local2 = _local2.sort();
            return (((_local1 + _local2.join("\n")) + "\n}"));
        }
        public function textStyleName(_arg1:Boolean):String{
            var _local3:String;
            var _local4:String;
            var _local5:Object;
            var _local2 = "";
            for (_local3 in m_properties) {
                if (TEXT_PROPERTIES[_local3]){
                    _local2 = (_local2 + (((_local3 + "_") + CSSProperty(m_properties[_local3]).valueOf()) + ","));
                };
            };
            _local2 = (_local2 + _arg1);
            if (!g_textStyleNames[_local2]){
                _local4 = ("style_" + TEXT_STYLESHEET.styleNames.length);
                _local5 = toTextFormatObject();
                if (_arg1){
                    delete _local5.marginLeft;
                    delete _local5.marginRight;
                };
                TEXT_STYLESHEET.setStyle(("." + _local4), _local5);
                g_textStyleNames[_local2] = _local4;
            };
            return (g_textStyleNames[_local2]);
        }
        public function compare(_arg1:CSSDeclaration):CSSPropertiesChangeList{
            var _local4:String;
            var _local2:Object = m_properties;
            var _local3:CSSPropertiesChangeList = new CSSPropertiesChangeList();
            if (!_arg1){
                for (_local4 in _local2) {
                    _local3.addChange(_local4);
                };
                return (_local3);
            };
            var _local5:Object = _arg1.m_properties;
            var _local6:Object = {};
            for (_local4 in _local2) {
                if (_local2[_local4] != _local5[_local4]){
                    _local3.addChange(_local4);
                };
                _local6[_local4] = true;
            };
            for (_local4 in _local5) {
                if (_local6[_local4]){
                } else {
                    if (_local2[_local4] != _local5[_local4]){
                        _local3.addChange(_local4);
                    };
                };
            };
            return (_local3);
        }
        public function setPropertyForKey(_arg1:CSSProperty, _arg2:String):void{
            m_properties[_arg2] = _arg1;
        }
        public function mergeCSSDeclaration(_arg1:CSSDeclaration, _arg2:Boolean=false, _arg3:Boolean=false):void{
            var _local5:CSSProperty;
            var _local6:CSSProperty;
            var _local7:String;
            var _local4:Object = _arg1.m_properties;
            for (_local7 in _local4) {
                _local6 = m_properties[_local7];
                if (((((_arg2) && (!(INHERITABLE_PROPERTIES[_local7])))) && (!(((_local6) && (_local6.inheritsValue())))))){
                } else {
                    _local5 = _local4[_local7];
                    if (((((((_arg3) && (_local6))) && (!(_local6.isAuto())))) && (!(_local5.important())))){
                    } else {
                        if (((((_local6) && (_local6.important()))) && (((!(_local5.important())) || (_arg3))))){
                        } else {
                            m_properties[_local7] = _local5;
                        };
                    };
                };
            };
        }
        public function getValueForKey(_arg1:String):CSSProperty{
            return (m_properties[_arg1]);
        }
        public function inheritCSSDeclaration(_arg1:CSSDeclaration):void{
            mergeCSSDeclaration(_arg1, true);
        }
        public function properties():Object{
            return (m_properties);
        }
        function setValueForKeyDefinedInFile(_arg1:String, _arg2:String, _arg3:String="", _arg4:Boolean=false):void{
            var _local7:Object;
//			if(_arg2=="color"){
//				trace("hello");
//			}
//			if(_arg2=="backgroundColor"){
//				trace("hello");
//			}
            var _local5:Object = CSSPropertyCache.propertyForKeyValue(_arg2, _arg1, _arg3, _arg4);
            if ((_local5 is CSSProperty)){
                m_properties[_arg2] = _local5;
                return;
            };
            if ((_local5 is CSSParsingResult)){
                _local7 = _local5.properties();
                for (_arg2 in _local7) {
                    m_properties[_arg2] = _local7[_arg2];
                };
                return;
            };
            var _local6 = (("c Parser for key \"" + _arg2) + "\" returned ");
            _local6 = (_local6 + ((_local5 == null)) ? ((("null. Perhaps you didn't define the " + "parser method as static? Or you probably gave the parser method ") + "a wrong name. Or you even forgot to implement it. Double-check ") + "and retry!") : "value of wrong type.");
            _local6 = (_local6 + "Parsing property via DefaultParser (probably as String).");
            _local5 = DefaultParser.parseAnything(_arg1, _arg3);
            m_properties[_arg2] = _local5;
            log(_local6);
        }
        public function hasStyle(_arg1:String):Boolean{
            return (!((m_properties[_arg1] == null)));
        }
        public function toComputedStyles():ComputedStyles{
            var _local2:String;
            var _local1:ComputedStyles = new ComputedStyles();
            for (_local2 in m_properties) {
                _local1[_local2] = CSSProperty(m_properties[_local2]).valueOf();
            };
            return (_local1);
        }
        public function getStyle(_arg1:String):CSSProperty{
            return (m_properties[_arg1]);
        }
        public function clone():CSSDeclaration{
            var _local2:String;
            var _local1:CSSDeclaration = new CSSDeclaration();
            for (_local2 in m_properties) {
                _local1.m_properties[_local2] = m_properties[_local2];
            };
            return (_local1);
        }
        public function setStyle(_arg1:String, _arg2:String=null, _arg3:Boolean=false):void{
            if (!_arg2){
                ((m_properties[_arg1]) && (delete m_properties[_arg1]));
                return;
            };
            setValueForKeyDefinedInFile(_arg2, _arg1, "", _arg3);
        }

        protected static function registerDefaultProperties():Boolean{
            registerPropertyCollection(Background);
            registerPropertyCollection(Border);
            registerPropertyCollection(DisplayPosition);
            registerPropertyCollection(reprise.css.propertyparsers.Font);
            registerPropertyCollection(Margin);
            registerPropertyCollection(Padding);
            registerPropertyCollection(ScrollbarProperties);
            registerPropertyCollection(Filters);
            registerPropertyCollection(Transition);
            return (true);
        }
        public static function CSSDeclarationFromObject(_arg1:Object):CSSDeclaration{
            var _local3:String;
            var _local2:CSSDeclaration = new (CSSDeclaration);
            for (_local3 in _arg1) {
                _local2.setStyle(_local3, _arg1[_local3]);
            };
            return (_local2);
        }
        private static function registerPropertyCollectionObject(_arg1:Object, _arg2:Object):void{
            var _local4:String;
            var _local5:Object;
            var _local3:Object = ((_arg2.TRANSITION_SHORTCUTS) || ({}));
            for (_local4 in _arg1) {
                _local5 = _arg1[_local4];
                g_propertyToParserTable[_local4] = _local5["parser"];
                if (_local5["inheritable"]){
                    INHERITABLE_PROPERTIES[_local4] = true;
                };
                if (_local5["transition"]){
                    TransitionVOFactory.registerProperty(_local4, _local5["transition"]);
                };
                if (_local3[_local4]){
                    CSSTransitionsManager.registerTransitionShortcut(_local4, _local3[_local4]);
                };
            };
        }
        public static function registerPropertyCollection(_arg1:Object):void{
            var _local2:Object = _arg1.KNOWN_PROPERTIES;
            registerPropertyCollectionObject(_local2, _arg1);
        }
        static function parserForProperty(_arg1:String):Function{
            var _local2:Function = g_propertyToParserTable[_arg1];
            if (_local2 == null){
                _local2 = DefaultParser.parseAnything;
                if (!m_thrownErrors[_arg1]){
                    log((("n No parser registered for css property \"" + _arg1) + "\". Parsing property via DefaultParser (probably as string)."));
                    m_thrownErrors[_arg1] = true;
                };
            };
            return (_local2);
        }

    }
}//package reprise.css 
